package com.google.code.mircle.core.transfers;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextArea;

import com.google.code.mircle.App;

public class NewDownloadDialog extends JDialog {

    private final JButton btnNewButton_1 = new JButton("Cancel");

    final App app;
    final DirectModel model;
    final DirectView view;

    public NewDownloadDialog(final App app, final DirectModel model, final DirectView view) {
        final NewDownloadDialog that = this;

        this.app = app;
        this.model = model;
        this.view = view;

        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        setModal(true);

        setBounds(100, 100, 467, 315);

        GridBagLayout gridBagLayout = new GridBagLayout();
        gridBagLayout.rowWeights = new double[] { 0.0, 1.0, 0.0 };
        gridBagLayout.columnWeights = new double[] { 1.0, 1.0 };
        getContentPane().setLayout(gridBagLayout);

        JLabel lblDirectDownload = new JLabel();
        lblDirectDownload.setText("URL or Magnet");
        GridBagConstraints gbc_lblDirectDownload = new GridBagConstraints();
        gbc_lblDirectDownload.gridwidth = 2;
        gbc_lblDirectDownload.insets = new Insets(0, 0, 5, 0);
        gbc_lblDirectDownload.anchor = GridBagConstraints.NORTHWEST;
        gbc_lblDirectDownload.gridx = 0;
        gbc_lblDirectDownload.gridy = 0;
        getContentPane().add(lblDirectDownload, gbc_lblDirectDownload);

        final JTextArea textArea = new JTextArea();
        GridBagConstraints gbc_textArea = new GridBagConstraints();
        gbc_textArea.gridwidth = 2;
        gbc_textArea.insets = new Insets(0, 0, 5, 0);
        gbc_textArea.fill = GridBagConstraints.BOTH;
        gbc_textArea.gridx = 0;
        gbc_textArea.gridy = 1;
        getContentPane().add(textArea, gbc_textArea);

        JButton btnNewButton = new JButton("OK");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                download(textArea.getText());
                that.dispose();
            }
        });

        GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
        gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
        gbc_btnNewButton.gridx = 0;
        gbc_btnNewButton.gridy = 2;
        getContentPane().add(btnNewButton, gbc_btnNewButton);
        GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
        gbc_btnNewButton_1.insets = new Insets(0, 0, 5, 0);
        gbc_btnNewButton_1.gridx = 1;
        gbc_btnNewButton_1.gridy = 2;
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                that.dispose();
            }
        });
        getContentPane().add(btnNewButton_1, gbc_btnNewButton_1);
    }

    void download(String url) {
        app.mircle(url);
    }

}
